home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_Rescale.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  3KB  |  144 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. VOID __regargs
  10. LTP_ResetListViewTextAttrs(ObjectNode *group)
  11. {
  12.     ObjectNode *node;
  13.  
  14.     SCANGROUP(group,node)
  15.     {
  16.         if(node -> Type == GROUP_KIND)
  17.             LTP_ResetGroups(node);
  18.         else
  19.         {
  20.             if(node -> Type == LISTVIEW_KIND && node -> Special . List . TextAttr)
  21.                 node -> Special . List . TextAttr = NULL;
  22.         }
  23.     }
  24. }
  25.  
  26. VOID __regargs
  27. LTP_Rescale(LayoutHandle *handle,BOOLEAN trimWidth,BOOLEAN trimHeight)
  28. {
  29.     STATIC struct TextAttr topazAttr =
  30.     {
  31.         "topaz.font",
  32.         8,
  33.         FS_NORMAL,
  34.         FPF_ROMFONT | FPF_DESIGNED
  35.     };
  36.  
  37.     LONG    oldWidth;
  38.     LONG    oldHeight;
  39.     UBYTE    glyph;
  40.     LONG    glyphWidth;
  41.     LONG    count;
  42.     LONG    i;
  43.     LONG    total;
  44.     BOOLEAN found;
  45.  
  46.     oldWidth    = handle -> GlyphWidth;
  47.     oldHeight    = handle -> RPort . TxHeight;
  48.  
  49.     LTP_ResetListViewTextAttrs(handle -> TopGroup);
  50.  
  51.     if(handle -> CloseFont)
  52.     {
  53.         CloseFont(handle -> RPort . Font);
  54.  
  55.         handle -> CloseFont = FALSE;
  56.     }
  57.  
  58.     if(handle -> TextAttr == &topazAttr)
  59.         return;
  60.     else
  61.     {
  62.         if(!Stricmp(handle -> TextAttr -> ta_Name,"topaz.font") && handle -> TextAttr -> ta_YSize == 8)
  63.             return;
  64.     }
  65.  
  66.     /* GfxBase -> DefaultFont is guaranteed not to ever be removed from
  67.      * memory,so we use that fact...
  68.      */
  69.  
  70.     LTP_SetFont(handle,GfxBase -> DefaultFont);
  71.  
  72.     handle -> TextAttr            = &handle -> CopyTextAttr;
  73.     handle -> CopyTextAttr . tta_Name    = handle -> RPort . Font -> tf_Message . mn_Node . ln_Name;
  74.     handle -> CopyTextAttr . tta_YSize    = handle -> RPort . TxHeight;
  75.     handle -> CopyTextAttr . tta_Style    = handle -> RPort . Font -> tf_Style;
  76.     handle -> CopyTextAttr . tta_Flags    = handle -> RPort . TxFlags;
  77.  
  78.     if(handle -> RPort . Font -> tf_Style & FSF_TAGGED)
  79.         handle -> CopyTextAttr . tta_Tags = ((struct TextFontExtension *)handle -> RPort . Font -> tf_Extension) -> tfe_Tags;
  80.  
  81.     FOREVER
  82.     {
  83.         count = 0;
  84.         total = 0;
  85.  
  86.         for(i = 32 ; i < 127 ; i++)
  87.         {
  88.             glyph = i;
  89.             total += TextLength(&handle -> RPort,&glyph,1);
  90.             count++;
  91.         }
  92.  
  93.         for(i = 160 ; i < 256 ; i++)
  94.         {
  95.             glyph = i;
  96.             total += TextLength(&handle -> RPort,&glyph,1);
  97.             count++;
  98.         }
  99.  
  100.         glyphWidth = total / count;
  101.  
  102.         found = TRUE;
  103.  
  104.         if(trimWidth && (glyphWidth >= oldWidth))
  105.             found = FALSE;
  106.  
  107.         if(trimHeight && (handle -> RPort . TxHeight >= oldHeight))
  108.             found = FALSE;
  109.  
  110.         if(found)
  111.         {
  112.             handle -> GlyphWidth    = glyphWidth;
  113.             handle -> Rescaled    = TRUE;
  114.  
  115.             if(glyphWidth <= 8)
  116.                 handle -> InterWidth = 4;
  117.             else
  118.                 handle -> InterWidth = glyphWidth / 2;
  119.  
  120.             if(handle -> RPort . TxHeight <= 8)
  121.                 handle -> InterHeight = 2;
  122.             else
  123.                 handle -> InterHeight = handle -> RPort . TxHeight / 4;
  124.  
  125.             LTP_ResetGroups(handle -> TopGroup);
  126.  
  127.             return;
  128.         }
  129.  
  130.         if(handle -> TextAttr == &topazAttr)
  131.             return;
  132.         else
  133.         {
  134.             if(!Stricmp(handle -> TextAttr -> ta_Name,"topaz.font") && handle -> TextAttr -> ta_YSize == 8)
  135.                 return;
  136.         }
  137.  
  138.         LTP_SetFont(handle,OpenFont(&topazAttr));
  139.  
  140.         handle -> TextAttr    = &topazAttr;
  141.         handle -> CloseFont    = TRUE;
  142.     }
  143. }
  144.